package com.yanfan.energybilling.controller;

import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.energybilling.domain.DeviceThingsEnergy;
import com.yanfan.energybilling.service.DeviceThingsEnergyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author caijinkang
 * @date 2022年09月28日 11:10
 *
 */
@RestController
@RequestMapping("/energyBuild")
@Api(tags = "能耗绑定设置")
public class DeviceThingsEnergyController extends BaseController {
    @Autowired
    private DeviceThingsEnergyService deviceThingsEnergyService;

    /**
     * 查询区域下对应的设备
     *
     * @return 查询结果
     */
    @ApiOperation("查询区域下对应的设备")
    @GetMapping("/findBindDeviceEnergy")
    public AjaxResult findBindDeviceEnergy(@ApiParam(name = "type", value = "选择类型") @RequestParam(required = false) Integer type, @ApiParam(name = "id", value = "车间id") @RequestParam Integer id, @ApiParam(name = "deviceName", value = "设备名称") @RequestParam(required = false) String deviceName, @ApiParam(name = "pageNum", value = "当前页") @RequestParam Integer pageNum, @ApiParam(name = "pageSize", value = "页条数") @RequestParam Integer pageSize) {
        return deviceThingsEnergyService.findBindDeviceEnergy(type, id, deviceName, pageNum, pageSize);
    }

    @ApiOperation("查询区域下对应的设备")
    @GetMapping("/findBindDeviceByBuildingId/{buildingId}")
    public AjaxResult findBindDeviceByBuildingId(@PathVariable("buildingId") Long buildingId) {
        return success(deviceThingsEnergyService.findBindDeviceByBuildingId(buildingId));
    }

    @ApiOperation("根据设备id查询物模型下拉孔")
    @GetMapping("/findIotThingsByDeviceId")
    public AjaxResult findIotThingsByDeviceId(@ApiParam(name = "deviceId", value = "设备id") @RequestParam(required = false) Integer deviceId, @ApiParam(name = "name", value = "物模型名称") @RequestParam(required = false) String name,@ApiParam(name = "serialNumber", value = "设备编号") @RequestParam(required = false) String serialNumber) {
        return AjaxResult.success(deviceThingsEnergyService.findIotThingsByDeviceId(deviceId, name,serialNumber));
    }

    @ApiOperation("新增设备区域绑定")
    @PostMapping("/addBindDeviceEnergy")
    public AjaxResult addBindDeviceEnergy(@ApiParam(name = "deviceThingsEnergy", value = "设备区域绑定对象") @RequestBody DeviceThingsEnergy deviceThingsEnergy) {
        return deviceThingsEnergyService.addBindDeviceEnergy(deviceThingsEnergy);
    }

    @ApiOperation("获取设备绑定详情")
    @GetMapping("/getBindDeviceEnergy/{id}")
    public AjaxResult getBindDeviceEnergy( @PathVariable("id") Long id) {
        return success(deviceThingsEnergyService.queryById(Math.toIntExact(id)));
    }

    @ApiOperation("修改设备区域绑定")
    @PostMapping("/updateBindDeviceEnergy")
    public AjaxResult updateBindDeviceEnergy(@ApiParam(name = "deviceThingsEnergy", value = "设备区域绑定对象") @RequestBody DeviceThingsEnergy deviceThingsEnergy) {
        return deviceThingsEnergyService.updateBindDeviceEnergy(deviceThingsEnergy);
    }

    @ApiOperation("删除设备绑定能源")
    @DeleteMapping("/deleteBindDeviceEnergy")
    public AjaxResult deleteBindDeviceEnergy(@ApiParam(name = "workshopId", value = "车间id") @RequestParam(required = false) Integer workshopId, @ApiParam(name = "type", value = "能源类型") @RequestParam Integer type, @ApiParam(name = "id", value = "id") @RequestParam Integer id, @ApiParam(name = "thingsId", value = "物模型id") @RequestParam Integer thingsId) {
        return deviceThingsEnergyService.deleteBindDeviceEnergy(workshopId, type, id, thingsId);
    }
}
